package com.geo.ai.model;

import lombok.Data;
import lombok.Builder;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * AI请求模型
 * 
 * @author GEO Team
 * @version 1.0
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AIRequest {
    
    // 手动添加builder方法以解决编译问题
    public static AIRequestBuilder builder() {
        return new AIRequestBuilder();
    }
    
    public static class AIRequestBuilder {
        private String requestId;
        private String merchantId;
        private TaskType taskType;
        private String modelName;
        private List<Message> messages;
        private String systemPrompt;
        private String userInput;
        private String prompt;
        private Integer maxTokens;
        private Double temperature;
        private Boolean stream;
        private Map<String, Object> parameters;
        private LocalDateTime requestTime;
        
        public AIRequestBuilder requestId(String requestId) {
            this.requestId = requestId;
            return this;
        }
        
        public AIRequestBuilder merchantId(String merchantId) {
            this.merchantId = merchantId;
            return this;
        }
        
        public AIRequestBuilder taskType(TaskType taskType) {
            this.taskType = taskType;
            return this;
        }
        
        public AIRequestBuilder modelName(String modelName) {
            this.modelName = modelName;
            return this;
        }
        
        public AIRequestBuilder messages(List<Message> messages) {
            this.messages = messages;
            return this;
        }
        
        public AIRequestBuilder systemPrompt(String systemPrompt) {
            this.systemPrompt = systemPrompt;
            return this;
        }
        
        public AIRequestBuilder userInput(String userInput) {
            this.userInput = userInput;
            return this;
        }
        
        public AIRequestBuilder prompt(String prompt) {
            this.prompt = prompt;
            return this;
        }
        
        public AIRequestBuilder maxTokens(Integer maxTokens) {
            this.maxTokens = maxTokens;
            return this;
        }
        
        public AIRequestBuilder temperature(Double temperature) {
            this.temperature = temperature;
            return this;
        }
        
        public AIRequestBuilder stream(Boolean stream) {
            this.stream = stream;
            return this;
        }
        
        public AIRequestBuilder parameters(Map<String, Object> parameters) {
            this.parameters = parameters;
            return this;
        }
        
        public AIRequestBuilder requestTime(LocalDateTime requestTime) {
            this.requestTime = requestTime;
            return this;
        }
        
        public AIRequest build() {
            AIRequest aiRequest = new AIRequest();
            aiRequest.requestId = this.requestId;
            aiRequest.merchantId = this.merchantId;
            aiRequest.taskType = this.taskType;
            aiRequest.modelName = this.modelName;
            aiRequest.messages = this.messages;
            aiRequest.systemPrompt = this.systemPrompt;
            aiRequest.userInput = this.userInput;
            aiRequest.prompt = this.prompt;
            aiRequest.maxTokens = this.maxTokens;
            aiRequest.temperature = this.temperature;
            aiRequest.stream = this.stream;
            aiRequest.parameters = this.parameters;
            aiRequest.requestTime = this.requestTime;
            return aiRequest;
        }
    }
    
    /**
     * 请求ID
     */
    private String requestId;
    
    /**
     * 商家ID
     */
    private String merchantId;
    
    /**
     * 任务类型
     */
    private TaskType taskType;
    
    /**
     * 模型名称
     */
    private String modelName;
    
    /**
     * 消息列表（支持多轮对话）
     */
    private List<Message> messages;
    
    /**
     * 系统提示词
     */
    private String systemPrompt;
    
    /**
     * 用户输入内容
     */
    private String userInput;
    
    /**
     * 提示词
     */
    private String prompt;
    
    /**
     * 最大token数
     */
    private Integer maxTokens;
    
    /**
     * 温度参数（控制创造性）
     */
    private Double temperature;
    
    /**
     * 是否流式输出
     */
    private Boolean stream;
    
    /**
     * 额外参数
     */
    private Map<String, Object> parameters;
    
    /**
     * 请求时间
     */
    private LocalDateTime requestTime;
    
    /**
     * 错误信息
     */
    private String errorMessage;
    
    /**
     * 内容
     */
    private String content;
    
    /**
     * 任务ID
     */
    private String taskId;
    
    // 手动添加getter方法
    public String getUserInput() {
        return userInput;
    }
    
    public TaskType getTaskType() {
        return taskType;
    }
    
    public String getModelName() {
        return modelName;
    }
    
    public List<Message> getMessages() {
        return messages;
    }
    
    public Double getTemperature() {
        return temperature;
    }
    
    public String getErrorMessage() {
        return errorMessage;
    }
    
    public String getContent() {
        return content;
    }
    
    public String getContentId() {
        return taskId;
    }
    
    // 添加缺失字段的setter方法
    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }
    
    public void setContent(String content) {
        this.content = content;
    }
    
    public String getTaskId() {
        return taskId;
    }
    
    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }
    
    public String getRequestId() {
        return requestId;
    }
    
    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }
    
    /**
     * 任务类型枚举
     */
    public enum TaskType {
        CONTENT_GENERATION("内容生成"),
        KEYWORD_ANALYSIS("关键词分析"), 
        KEYWORD_EXPANSION("关键词扩展"),
        CONTENT_OPTIMIZATION("内容优化"),
        SENTIMENT_ANALYSIS("情感分析"),
        TEXT_SUMMARIZATION("文本摘要"),
        TRANSLATION("翻译"),
        QA_GENERATION("问答生成"),
        SEO_OPTIMIZATION("SEO优化"),
        COMPETITOR_ANALYSIS("竞品分析");
        
        private final String description;
        
        TaskType(String description) {
            this.description = description;
        }
        
        public String getDescription() {
            return description;
        }
    }
    
    /**
     * 消息对象
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Message {
        /**
         * 角色类型
         */
        private Role role;
        
        /**
         * 消息内容
         */
        private String content;
        
        /**
         * 消息时间戳
         */
        private LocalDateTime timestamp;
        
        /**
         * 角色枚举
         */
        public enum Role {
            SYSTEM("system"),
            USER("user"), 
            ASSISTANT("assistant");
            
            private final String value;
            
            Role(String value) {
                this.value = value;
            }
            
            public String getValue() {
                return value;
            }
        }
        
        // 手动添加getter方法
        public String getContent() {
            return content;
        }
        
        public Role getRole() {
            return role;
        }
        
        public LocalDateTime getTimestamp() {
            return timestamp;
        }
        
        // 手动添加setter方法
        public void setContent(String content) {
            this.content = content;
        }
        
        public void setRole(Role role) {
            this.role = role;
        }
        
        public void setTimestamp(LocalDateTime timestamp) {
            this.timestamp = timestamp;
        }
    }
}